import frappe
from typing import Optional

def patch_db_query():
    """给数据库查询打补丁"""
    from frappe.model.db_query import cast_name as original_cast_name
    from frappe.model.db_query import DatabaseQuery

    def patched_cast_name(column: str) -> str:
        """达梦数据库不需要类型转换"""
        if frappe.conf.db_type == "dm":
            return column
        return original_cast_name(column)

    # 应用补丁
    frappe.model.db_query.cast_name = patched_cast_name
    